/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.ComponentModel;

namespace DaveSexton.DocProject.InstallActions
{
	internal static class Log
	{
		private static readonly EventLog log = new EventLog("Application", ".", "DocProject");

		public static void Exception(Exception ex, string format, params object[] args)
		{
			if (args != null)
				format = string.Format(System.Globalization.CultureInfo.CurrentCulture, format, args);

			if (ex != null)
			{
				if (!string.IsNullOrEmpty(format))
					format = format + Environment.NewLine + Environment.NewLine + ex.ToString();
				else
					format = ex.ToString();
			}

			try
			{
				log.WriteEntry(format, EventLogEntryType.Error);
			}
			catch (Win32Exception) { }
		}

		public static void Write(string format, params object[] args)
		{
			if (args != null)
				format = string.Format(System.Globalization.CultureInfo.CurrentCulture, format, args);

			try
			{
				log.WriteEntry(format, EventLogEntryType.Information);
			}
			catch (Win32Exception) { }
		}

		public static void Warn(string format, params object[] args)
		{
			if (args != null)
				format = string.Format(System.Globalization.CultureInfo.CurrentCulture, format, args);

			try
			{
				log.WriteEntry(format, EventLogEntryType.Warning);
			}
			catch (Win32Exception) { }
		}
	}
}
